//
//  FirstViewController.m
//  MZJ
//
//  Created by XDD on 16/6/6.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "FirstViewController.h"
#import "TabBarViewController.h"

@interface FirstViewController () {
    
    NSInteger startTime_;
    NSMutableDictionary *dic;
    NSString *token;
}

@property (nonatomic, strong) NetWorkingSModel *model;
@property (nonatomic, strong) ModelViewController *modelViewController;
@property (nonatomic, strong) NSTimer *timer;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor whiteColor];
    

    
    UIImageView *firstImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    firstImageView.backgroundColor = [UIColor purpleColor];
    firstImageView.image = [UIImage imageNamed:@"homepage_img.jpg"];
    [self.view addSubview:firstImageView];
    
//    if (!_modelViewController) {
//        _modelViewController = [[ModelViewController alloc] init];
//        if (!_model) {
//            _model = [[NetWorkingSModel alloc] init];
//        }
//    }
    dic = [NSMutableDictionary dictionary];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    token = [user objectForKey:@"user_token"];
    
//    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//    dispatch_group_t group = dispatch_group_create();
//    dispatch_group_async(group, queue, ^{
//        [NSThread sleepForTimeInterval:3];
//        [self person_data_httprequest];
        
//        if (token.length != 0) {
//            
//            [dic setObject:token forKey:@"token"];
//            TabBarViewController *wei = [[TabBarViewController alloc]init];
//            [self presentViewController:wei animated:YES completion:nil];
//
//        }else {
//            LoginViewController *loginVC = [[LoginViewController alloc]init];
//            [self presentViewController:loginVC animated:YES completion:nil];
//
//        }
//        if (IsNilString([[NSUserDefaults standardUserDefaults] objectForKey:@"user_token"])) {
//                   }else {
//                   }

//    });

    startTime_ = 2;
    _timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(firstImageViewAction:) userInfo:nil repeats:YES];

}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
    //UIStatusBarStyleDefault = 0 黑色文字，浅色背景时使用
    //UIStatusBarStyleLightContent = 1 白色文字，深色背景时使用
}

//- (void)person_data_httprequest {
//    __weak typeof (self)weakSelf = self;
//    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString *token = [user objectForKey:@"user_token"];
//    
//    if (token.length != 0) {
//        
//        [dic setObject:token forKey:@"token"];
//    }
//    if (IsNilString([[NSUserDefaults standardUserDefaults] objectForKey:@"user_token"])) {
//        LoginViewController *loginVC = [[LoginViewController alloc]init];
//        [self presentViewController:loginVC animated:YES completion:nil];
//    }
//    else {
//        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//        [dic setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"user_token"] forKey:@"token"];
//        
//        [_model setBlockWithReturnBlock:^(id returnValue) {
//            if ([returnValue[@"statu"] integerValue] != 0) {
//                LoginViewController *loginVC = [[LoginViewController alloc]init];
//                [weakSelf presentViewController:loginVC animated:YES completion:nil];
//               
//            }else {
//                [weakSelf.modelViewController userInfo_data_save:@"useDetail.txt" responseObject:returnValue[@"result"]];
//                TabBarViewController *wei = [[TabBarViewController alloc]init];
//                [weakSelf presentViewController:wei animated:YES completion:nil];
//            }
////            NSLog(@"个人信息 = %@",returnValue);
//            
//        } WithErrorBlock:^(id errorCode) {
//            
//        }];
//        [weakSelf.model userGetUserinfo:dic];
//    }
//}

- (IBAction)firstImageViewAction:(id)sender {
//    NSLog(@"%ld",(long)startTime_);
    
    if (startTime_ > 0) {
        startTime_ -= 1;
    }
    if (startTime_ == 0) {
        [_timer setFireDate:[NSDate distantFuture]];
////        [self person_data_httprequest];
//        if (token.length != 0) {
//            
//            [dic setObject:token forKey:@"token"];
            TabBarViewController *wei = [[TabBarViewController alloc]init];
            [self presentViewController:wei animated:YES completion:nil];
//
//        }else {
//            LoginViewController *loginVC = [[LoginViewController alloc]init];
//            [self presentViewController:loginVC animated:YES completion:nil];
//            
//        }
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
